﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UI
{
    public partial class UserMessage : Form
    {
        BLL.Users  bLKM = new BLL.Users ();
        string currSearchContent = "";
        public UserMessage()
        {
            InitializeComponent();
        }

        private void UserMessage_Load(object sender, EventArgs e)
        {
            cmb1.Items.Add("员工号");
            cmb1.Items.Add("姓名");
            cmb1.Items.Add("联系方式");
            //cmb2.Items.Add("精确");
            //cmb2.Items.Add("类似于");
            bindGrudView();
        }
        public void bindGrudView()
        {
            dgvStaffMassage.DataSource = bLKM.select(currSearchContent);
        }

        private void btn4_Click(object sender, EventArgs e)
        {
            string searchField = "";
            switch (cmb1.SelectedItem.ToString())
            {
                case "员工号":
                    searchField = "UserID";
                    break;
                case "姓名":
                    searchField = "Name";
                    break;
                case "联系方式":
                    searchField = "Number";
                    break;
            }
            //if (cmb2.SelectedItem.ToString () != "类似于")
            //    currSearchContent = searchField + cmb2.SelectedItem.ToString() + "'" + textBox1.Text + "'";
            //else
                currSearchContent = searchField + " like '%" + textBox1.Text + "%'";
            bindGrudView();
        }

        private void btn3_Click(object sender, EventArgs e)
        {

            DialogResult dr = MessageBox.Show("确认删除该员工信息吗？", "确认删除", MessageBoxButtons.YesNo);
            if (dr == DialogResult.Yes)
            {
                bLKM.delete(dgvStaffMassage.CurrentRow.Cells[0].Value.ToString());
                bindGrudView();
            }
        }

        private void btn2_Click(object sender, EventArgs e)
        {
            FmUchange  frm = new FmUchange ();
            frm.UserID = dgvStaffMassage.CurrentRow.Cells[0].Value.ToString();
            frm.status = "修改";
            frm.MdiParent = this.MdiParent;
            frm.myParentErm = this;
            frm.Show();
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            FmUchange  frm = new FmUchange ();       
            frm.status = "添加";
            frm.MdiParent = this.MdiParent;
            frm.myParentErm = this;
            frm.Show();
        }

        private void cmb1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
